<?php

namespace App\Service\Common;

use App\Models\Kms\Album\AlbumResourceModel;
use App\Service\BaseService;

class PreviewService extends BaseService
{

    const RESOURCE_SOURCE_1    = 1;//kms分享
    const RESOURCE_SOURCE_TEXT = [
        self::RESOURCE_SOURCE_1 => "kms分享"
    ];

    /**
     * @param object $params
     * @return array
     */
    public static function resourceLists(object $params): array
    {
        switch ($params->type) {
            case self::RESOURCE_SOURCE_1:
                $albumResources = AlbumResourceModel::query()
                                                    ->whereIn("id", $params->resourceIds)->get()
                                                    ->map(function (AlbumResourceModel $albumResourceModel) {
                                                        return [
                                                            "originalUrl" => $albumResourceModel->originalUrl,
                                                            "type"        => $albumResourceModel->type,
                                                            "previewUrl"  => $albumResourceModel->previewUrl,
                                                            "size"        => $albumResourceModel->size
                                                        ];
                                                    })->values()->toArray();

                break;
            default:
                $albumResources = [];
                break;
        }

        return [
            "list" => $albumResources
        ];
    }

}
